<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> 
<title>专利协同服务网络平台</title>
<link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="${pageContext.request.contextPath}/js/jquery.js"></script>
<script src="${pageContext.request.contextPath}/js/cloud.js" type="text/javascript"></script>

<script language="javascript">
$(function(){
    $('.loginbox').css({'position':'absolute','left':($(window).width()-692)/2});
	$(window).resize(function(){  
    $('.loginbox').css({'position':'absolute','left':($(window).width()-692)/2});
    })  
});  
$(function(){
	$("#submit").click(function(){
		var message = $("#message");
		message.html("<font color='red'></font>");
		var phoneNumber=$("#phoneNumber").val();
		var password=$("#password").val();
		var userType=$("#userType")[0].options[$("#userType")[0].selectedIndex].value;
		if(phoneNumber!= null&& phoneNumber !=""){
  		  $.ajax({  
                url:"${pageContext.request.contextPath}/researcher/findUser.html", 
                type:"post",  
                data:{  
                    "phoneNumber":phoneNumber,
                    "userType":userType,
                },  
                dataType:"text",  
                success : function(data) {  
                	if(userType == 0){
            			message.html("<font color='red'>请选择您登录的角色类型</font>");
                    
                    } else {  
                    	if(data=='fail'){  
                        	message.html("<font color='red'>该手机号还没有注册</font>");
                		} else {
                			if(phoneNumber!="" && phoneNumber != null && password != "" && password != null){
                				$.ajax({
                			   		type: "POST",
                			   		url: "${pageContext.request.contextPath}/admin/login.html",  
                			   		data: $("#loginForm").serialize()+"&userType="+userType,
                			   		dataType:'text',
                			   		success:function(data) {
                			   			if(data == "fail") {
                			   				message.html("<font color='red'>账号或密码不正确!</font>");
                			   			}else if(data == "error"){
                			   				message.html("<font color='red'>您输入的信息不正确！</font>");
                			   			} else{
                			   				window.location='${pageContext.request.contextPath}/admin/redirect.do?userType='+data;
                			   			}
                			   		}
                			   	}); 
                			}else if((phoneNumber==""||phoneNumber==null)&&(password==""||password==null)){
                				message.html("<font color='red'>请输入账号和密码！</font>");
                			}else if(password==""||password==null){
                				message.html("<font color='red'>请输入密码！</font>");
                			}else if(phoneNumber==""||phoneNumber==null){
                				message.html("<font color='red'>请输入账号！</font>");
                			} //end if-else 
                		} //end if -else	
                   } 
                }//end success
            }); //end ajax
  	  }
		
	});
});	
$(document).ready(function(){
	var options = document.getElementsByName('opt');
	console.log("${userType}");
	for(var i=0;i<options.length;i++){
		 if(options[i].value == "${userType}"){
			options[i].selected='selected';
   		 	break;
		 }else{
			 options[0].selected='selected';
		 }
	}
});
</script> 

</head>
<body style="background-color:#1c77ac; background-image:url(${pageContext.request.contextPath}/images/light.png); background-repeat:no-repeat; background-position:center top; overflow:hidden;">
	 <div id="mainBody">
	      <div id="cloud1" class="cloud"></div>
	      <div id="cloud2" class="cloud"></div>
   	 </div>  
	 <div class="logintop">    
   		 <span>欢迎登录专利协同服务网络平台</span>    
     </div>
    <div class="loginbody">
	    <span class="systemlogo"></span> 
	    <div class="loginbox">
	    	<form action="" id="loginForm">
			    <ul>
				    <li><input id="phoneNumber" name="phoneNumber" type="text" class="loginuser" placeholder="手机号/用户名"/></li>
				    <li>
				    	<input id="password" name="password" type="password" class="loginpwd" placeholder="密码"/>
				    	<br><a href="${pageContext.request.contextPath}/redirect/toForget.html" style="color: #175199; text-decoration: none;margin-left:290px ">
									忘记密码</a></li>
				    </li>
				    <li><input type="button" class="loginbtn" value="登录"  id="submit"  />	
				    <label>
				    	 <select id="userType" style ="border: 1px solid #277de2;">
				   			  <option name="opt" value="1002" selected="selected">科研人员</option>
				   			  <c:forEach items="${dicUserTypes}" var="userType" begin="1">
				   			  	 <option name="opt" value="${userType.typeCode}">${userType.description}</option>
				   			  </c:forEach>
				    	 </select>
				    </label>
					<div>
						还没账号？
						<a style="color:#175199" href="${pageContext.request.contextPath}/researcher/toRegist.html">
									立即注册</a>
					</div>				
				    <!-- <label><a href="#">忘记密码？</a></label></li> -->
				    <li><span id="message" style="font-size:20px;margin-top:-10px;"></span></li>
			    </ul>
		    </form>
	    </div>
    </div>
</body>
</html>